<template>
  <div class="app-container">
    <div class="menu-container">
      <el-form :inline="true" style="float: left;">
        <el-button size="mini" type="primary" @click="addTag()">添加标签</el-button>
      </el-form>

    </div>
    <el-table v-loading="listLoading" :data="page.records" border fit highlight-current-row style="width: 100%" height="500">
      <el-table-column align="center" label="ID" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="标签名称">
        <template slot-scope="scope">
          <el-button type="text" size="small" icon="el-icon-edit" @click="modifyTag(scope.row)">
            {{ scope.row.name }}
          </el-button>
        </template>
      </el-table-column>

      <el-table-column width="100px" align="center" label="状态">
        <template slot-scope="scope">
          <span>{{ scope.row.state_desc }}</span>
        </template>
      </el-table-column>

      <el-table-column width="100px" align="center" label="排序">
        <template slot-scope="scope">
          <span>{{ scope.row.show_order }}</span>
        </template>
      </el-table-column>

      <el-table-column width="100px" align="center" label="创建时间">
        <template slot-scope="scope">
          <span>{{ scope.row.create_time }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination v-show="page.recordsTotal>0" :total="page.recordsTotal" :page.sync="listQuery.pageNum" :page-sizes="[50, 100]" :limit.sync="listQuery.pageSize" @pagination="getList" />

    <el-dialog :visible.sync="dialogFormVisible" :title="dialogTitle" log- width="80%">
      <tag-detail :is-edit="isEdit" :current-id="currentTeamId" @successTeamOperate="handleTeamOperate"/>
    </el-dialog>

  </div>
</template>

<script>
import { fetchList } from '@/api/tag'
import Pagination from '@/components/Pagination'
import TagDetail from './components/TagDetail'

export default {
  name: 'SerieList',
  components: { Pagination, TagDetail },
  data() {
    return {
      total: 0,
      listLoading: true,
      listQuery: {
        nickname: '',
        user_state: '',
        user_from: '',
        pageNum: 1,
        pageSize: 100
      },
      isEdit: false,
      dialogTitle: '新增标签',
      dialogFormVisible: false,
      dialogMemberFormVisible: false,
      currentTeamId: undefined,
      userStateOptions: [{ label: '普通用户', value: 0 }, { label: '客户经理', value: 1 }, { label: '标签领导', value: 2 }, { label: '普通生产者', value: 3 }],
      userFromOptions: [{ label: '普通用户', value: 0 }, { label: '客户经理', value: 1 }, { label: '生产', value: 2 }],
      page: { pageNum: 1, pageSize: 100, pageTotal: 0, recordsTotal: 0, records: [] }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleTeamOperate() {
      this.dialogFormVisible = false
      this.getList()
    },
    addTag() {
      this.isEdit = false
      this.currentTeamId = undefined
      this.dialogTitle = '新建标签'
      this.dialogFormVisible = true
    },
    modifyTag(team) {
      this.isEdit = true
      this.currentTeamId = team.id
      this.dialogTitle = '编辑标签'
      this.dialogFormVisible = true
    },
    modifyMembers(team) {
      this.currentTeamId = team.id
      this.isEdit = true
      this.dialogMemberFormVisible = true
    },
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        const data = response.data
        if (data.code !== 0) {
          this.$message.error(data.msg)
        }
        this.page = data.data
        this.listLoading = false
      })
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
